package cn.panda.edu.controller;

import cn.panda.edu.model.EnrollStudents;
import cn.panda.edu.service.EnrollStudentsService;
import cn.panda.edu.util.Constant;
import cn.panda.edu.util.ResultDataUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/admin")
@Api(description="招生计划")
public class ManageEnrollStuController {

	@Autowired
	private EnrollStudentsService enrollStudentsService;

	
	/**
	 * 
	* @Title: StudentPlanAdd 
	* @Description: TODO(添加招生计划信息) 
	* @param eStudents
	* @return  
	* Map<String,Object>
	 */
	@ApiOperation(value ="添加招生计划信息", notes ="")
	@ApiImplicitParam(name ="eStudents", value ="招生计划实体类EnrollStudents", required =false, dataType ="EnrollStudents", paramType ="form")
	@RequestMapping(value ="/StudentPlanAdd", method =RequestMethod.POST)
	public Map<String, Object> StudentPlanAdd(EnrollStudents eStudents){
		Map<String, Object> map = new HashMap<>();
		eStudents.setEnrollCreateDate(new Date());
		int result = enrollStudentsService.insertSelective(eStudents);
		if(result > 0) {
			map = ResultDataUtil.resData(200, "添加招生计划成功", null);
		} else {
			map = ResultDataUtil.resData(500, "添加招生计划失败", null);
		}
		return map;
		
	}
	
	/**
	 * 
	* @Title: 根据主键查询生计划信息
	* @Description: TODO(根据主键查询生计划信息) 
	* @param enrollId
	* @return  
	* Map<String,Object>
	 */
	@ApiOperation(value ="根据主键查询生计划信息",notes ="")
	@ApiImplicitParam(name ="enrollId", value ="招生计划编号", required =true, dataType ="int", paramType ="form")
	@RequestMapping(value ="/StudentPlanSel", method =RequestMethod.POST)
	public Map<String, Object> StudentPlanSel(Integer enrollId){
		Map<String, Object> map = new HashMap<>();
		EnrollStudents eStudent = enrollStudentsService.selectByPrimaryKey(enrollId);
		if(eStudent == null) {
			map = ResultDataUtil.resData(500, "查询失败", null);
		} else {
			map = ResultDataUtil.resData(200, "查询成功", eStudent);
		}
		return map;
		
	}
	
	/**
	 * 
	* @Title: 删除招生计划信息 
	* @Description: TODO(删除招生计划信息) 
	* @param enrollId
	* @return  
	* Map<String,Object>
	 */
	@ApiOperation(value ="删除招生计划信息", notes ="")
	@ApiImplicitParam(name ="enrollId", value ="招生编号", required =true, dataType ="int", paramType ="form")
	@RequestMapping(value ="/StudentPlanDel", method =RequestMethod.POST)
	public Map<String, Object> StudentPlanDel (Integer enrollId){
		Map<String, Object> map = new HashMap<>();
		int result = enrollStudentsService.deleteByPrimaryKey(enrollId);
		if(result > 0) {
			map = ResultDataUtil.resData(200, "删除成功", null);
		} else {
			map = ResultDataUtil.resData(500, "删除失败", null);
			map.put("status", 404);
		}
		return map;
		
	}
	
	/**
	 * 
	* @Title: 修改招生计划信息 
	* @Description: TODO(修改招生计划信息) 
	* @param eStudents
	* @return  
	* Map<String,Object>
	 */
	@ApiOperation(value ="修改招生计划信息", notes ="")
	@ApiImplicitParam(name ="eStudents", value ="招生计划实体类EnrollStudents", required =false, dataType ="EnrollStudents", paramType ="form")
	@RequestMapping(value ="/StudentPlanUp", method =RequestMethod.POST)
	public Map<String, Object> StudentPlanUp(EnrollStudents eStudents){
		Map<String, Object> map = new HashMap<>();
		eStudents.setEnrollModifyDate(new Date());
		int result = enrollStudentsService.updateByPrimaryKeySelective(eStudents);
				if(result > 0) {
					map = ResultDataUtil.resData(200, "修改成功", null);
				} else {
					map = ResultDataUtil.resData(500, "修改失败", null);
				}
				return map;
		
	}
	
	/**
	 * 
	* @Title: 查询招生计划   分页 
	* @Description: TODO(分页+根据专业名称模糊查询招生计划) 
	* @param majorName
	* @param pageIndex
	* @return  
	* PageInfo<EnrollStudents>
	 */
	@ApiOperation(value="查询招生计划   分页" , notes="分页+模糊查询招生计划")//用以指明api名称 
	@ApiImplicitParams({
		@ApiImplicitParam(name = "majorName", value = "专业名称", required = false, dataType = "String", paramType="form"),
		@ApiImplicitParam(name = "pageIndex", value ="当前页码", required =true, dataType = "int", paramType="form")
	})
	@RequestMapping(value = "/StudentPlanFy", method = RequestMethod.POST)
	public Object StudentPlanFy(String majorName,int pageIndex){
		PageInfo<EnrollStudents> ePageInfo = enrollStudentsService.selectByPageAndSelective(majorName, pageIndex, Constant.PAGE_SIZE);
		
		return ResultDataUtil.resData(200, "", ePageInfo);
		
	}
}